package com.xlhl.init.utils;

import com.xlhl.init.common.CustomHttpCode;
import com.xlhl.init.exceptipn.BusinessException;

/**
 * @author xlhl
 */
public class ThrowUtil {

    /**
     * 条件成立则抛出异常
     *
     * @param condition
     * @param message
     */
    public static void throwIf(boolean condition, String message) {
        throwIf(condition, new BusinessException(message));
    }

    /**
     * 条件成立则抛出异常
     *
     * @param condition
     * @param httpCode
     */
    public static void throwIf(boolean condition, CustomHttpCode httpCode) {
        throwIf(condition, new BusinessException(httpCode));
    }

    /**
     * 条件成立则抛出异常
     *
     * @param condition
     * @param httpCode
     * @param message
     */
    public static void throwIf(boolean condition, CustomHttpCode httpCode, String message) {
        throwIf(condition, new BusinessException(httpCode, message));
    }

    /**
     * 条件成立则抛出异常
     *
     * @param condition
     * @param e
     */
    public static void throwIf(boolean condition, RuntimeException e) {
        if (condition) {
            throw e;
        }
    }
}
